<?php
require_once 'View/ApiView.php';
require_once 'Model/APIModel.php';
class ApiController{
	private $apiView;
	private $apiModel;
	public function __construct($a_model){
		$this->apiView = new APIView();
		$this->apiModel = $a_model;
	}
	
	public function DoControll(){
		switch ($this->apiView->getRequestMethod()){
			case APIView::REQUEST_METHOD_GET:
				return $this->GetRequest();
				break;
			default:
				
				break;
		}
	}
	
	public function GetRequest(){
		$idValue = $this->apiView->GetIDValue();
		if($this->apiView->isValidUri()){
			if(is_null($idValue)){
				return $this->apiView->FormatResult($this->apiModel->GetAll());	
			}
			return $this->apiView->FormatResult($this->apiModel->GetByID($idValue));
		}
		return $this->apiView->GetNotFoundCode();
	}
}
